//
//  BlankCell.m
//  inquiry
//
//  Created by 高宇 on 2020/6/16.
//  Copyright © 2020 高宇. All rights reserved.
//

#import "BlankCell.h"
#import "GXToast.h"

@implementation BlankCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    
    _textView.delegate = self;
    
    _placeHolderLabel = [[UILabel alloc] initWithFrame:CGRectMake(5, 5,self.frame.size.width-30, 20)];
    _placeHolderLabel.textAlignment = NSTextAlignmentLeft;
    _placeHolderLabel.font = [UIFont systemFontOfSize:14];
    _placeHolderLabel.text = @"请输入你的答案";
    _placeHolderLabel.font = [UIFont systemFontOfSize:18];
    _placeHolderLabel.textColor = [UIColor colorWithRed:204/255.0 green:204/255.0 blue:204/255.0 alpha:1.0];
    [_textView addSubview:_placeHolderLabel];
}

- (IBAction)topClick:(id)sender {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];  //数据都存在这个字典里
//    if (_lastValue) {
//        [dic setValue:@[self.textView.text] forKey:@"solutionId"];
//        [dic setValue:self.topicIndex forKey:@"topicIndex"];
//        [dic setValue:self.topTopicIndex forKey:@"topTopicIndex"];
//    }
    
    if (self.topBlcok) {
        self.topBlcok(dic);
    }
}

- (IBAction)nextClick:(id)sender {
    if (self.textView.text.length == 0) {
        [GXToast showText:@"请输入你的答案"];
        return;
    }
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];  //数据都存在这个字典里
    [dic setValue:@[self.textView.text] forKey:@"solutionId"];
    [dic setValue:self.topicIndex forKey:@"topicIndex"];
    [dic setValue:self.topTopicIndex forKey:@"topTopicIndex"];
    
    if (self.nextBlcok) {
        self.nextBlcok(dic);
    }
}

- (void)lastClick{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setValue:@[self.textView.text] forKey:@"solutionId"];
    [dic setValue:self.topicIndex forKey:@"topicIndex"];
    [dic setValue:self.topTopicIndex forKey:@"topTopicIndex"];
    
    if (self.lastBlcok) {
        self.lastBlcok(dic);
    }
}

- (void)textViewDidChange:(UITextView *)textView
{
    if (textView.text.length == 0 )
    {
        _placeHolderLabel.text = @"请输入内容";
    }
    else
    {
        _placeHolderLabel.text = @"";
    }
    
    if (_lastValue) {
        [self lastClick];
    }
}

@end
